package com.codefactory.geneticalgorithm.view;

import com.codefactory.geneticalgorithm.MachineInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author kurbatov
 */
public class RepairScheduleTableModel extends AbstractTableModel{

    private Map<MachineInfo, Vector<Vector<Boolean>>> data = new HashMap<MachineInfo, Vector<Vector<Boolean>>>();
    
    public int getRowCount() {
        return data.size();
    }

    public int getColumnCount() {
        return 13;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        MachineInfo target = new ArrayList<MachineInfo>(data.keySet()).get(rowIndex);
        if(columnIndex == 0){
            return target.getName();
        }else{
            String result = "";
            Boolean repair = data.get(target).get(0).get(rowIndex);
            Boolean maintenance = data.get(target).get(1).get(rowIndex);
            if(repair){
                result += "К";
            }
            if(maintenance){
                result += "Т";
            }
            return result;
        }
    }

    public Map<MachineInfo, Vector<Vector<Boolean>>> getData() {
        return data;
    }

    public void setData(Map<MachineInfo, Vector<Vector<Boolean>>> data) {
        fireTableDataChanged();
        this.data = data;
    }
    
}
